package cn.edu.zut.request;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @author Davey chan
 */
public class URLDEMO {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String username="张三";
//        URL编码
        String encode = URLEncoder.encode(username, "utf-8");
        System.out.println(encode);
//        URL解码
//        String decode= URLDecoder.decode(encode,"utf-8");
//        Tomcat的编码方式
        String decode= URLDecoder.decode(encode,"ISO-8859-1");
        System.out.println(decode);
//        转换成字节数组,编码
        byte[] bytes=decode.getBytes("ISO-8859-1");
//        for(byte b:bytes){
//            System.out.print(b+" ");
//        }
//        4,将字节数组转变成字符串，解码
        String s=new String(bytes,"utf-8");
        System.out.println(s);

    }
}
